Repository navigation
feat: add command - #337
Conversation
🦋 Changeset detectedLatest commit: 896cd5d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedThe pull request is closed. WalkthroughThis update introduces a structured system for managing and validating addon compatibility in Better-T Stack projects. It adds utilities for reading, writing, and updating a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ProjectConfig
participant AddonUtils
participant BTSConfig
User->>CLI: Run "add" command (with/without addons)
CLI->>ProjectConfig: Detect project config (if needed)
ProjectConfig-->>CLI: Return config or null
CLI->>AddonUtils: Get compatible addons (if needed)
AddonUtils-->>CLI: Return list of compatible addons
CLI->>User: Prompt for addons (if not provided)
User-->>CLI: Select addons
CLI->>AddonUtils: Validate addon compatibility
AddonUtils-->>CLI: Compatibility result
CLI->>BTSConfig: Update bts.jsonc with new addons
BTSConfig-->>CLI: Confirmation
CLI->>CLI: Install dependencies (if requested)
CLI->>User: Output success or error message
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
packages/types/src/index.ts (1)
159-160: Unify duplicate union types
AvailablePackageManagersduplicates thePackageManagerunion. Consider aliasing it instead:-export type AvailablePackageManagers = keyof typeof dependencyVersionMap; +export type AvailablePackageManagers = PackageManager;apps/cli/src/prompts/add-addons-prompt.ts (1)
74-74: Consider making addon selection optional.Setting
required: trueforces users to select at least one addon, but they might want to cancel without selecting any.- required: true, + required: false,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (22)
apps/cli/README.md(5 hunks)apps/cli/package.json(1 hunks)apps/cli/src/constants.ts(1 hunks)apps/cli/src/helpers/project-generation/add-addons.ts(1 hunks)apps/cli/src/helpers/project-generation/create-project.ts(2 hunks)apps/cli/src/helpers/project-generation/detect-project-config.ts(1 hunks)apps/cli/src/index.ts(3 hunks)apps/cli/src/prompts/add-addons-prompt.ts(1 hunks)apps/cli/src/types.ts(1 hunks)apps/cli/src/utils/addon-compatibility.ts(1 hunks)apps/cli/src/utils/bts-config.ts(1 hunks)apps/cli/tsdown.config.ts(1 hunks)apps/web/package.json(3 hunks)apps/web/public/example-bts.jsonc(1 hunks)apps/web/public/schema.json(1 hunks)apps/web/scripts/generate-schema.ts(1 hunks)apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx(2 hunks)apps/web/src/app/(home)/showcase/page.tsx(3 hunks)package.json(1 hunks)packages/types/package.json(1 hunks)packages/types/src/index.ts(1 hunks)packages/types/tsconfig.json(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
apps/cli/src/helpers/project-generation/create-project.ts (1)
apps/cli/src/utils/bts-config.ts (1)
writeBtsConfig(9-52)
apps/web/src/app/(home)/showcase/page.tsx (1)
apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx (1)
ShowcaseItem(17-125)
apps/web/scripts/generate-schema.ts (1)
packages/types/src/index.ts (10)
DatabaseSchema(3-5)ORMSchema(8-10)BackendSchema(13-15)RuntimeSchema(18-22)FrontendSchema(25-38)AddonsSchema(41-43)ExamplesSchema(46-48)PackageManagerSchema(51-53)DatabaseSetupSchema(56-66)APISchema(69-69)
apps/cli/src/helpers/project-generation/add-addons.ts (6)
packages/types/src/index.ts (3)
AddInput(113-118)Addons(44-44)ProjectConfig(124-141)apps/cli/src/helpers/project-generation/detect-project-config.ts (2)
isBetterTStackProject(35-43)detectProjectConfig(6-33)apps/cli/src/helpers/project-generation/template-manager.ts (1)
setupAddonsTemplate(547-583)apps/cli/src/helpers/setup/addons-setup.ts (1)
setupAddons(8-48)apps/cli/src/utils/bts-config.ts (1)
updateBtsConfig(74-113)apps/cli/src/helpers/project-generation/install-dependencies.ts (1)
installDependencies(7-32)
apps/cli/src/prompts/add-addons-prompt.ts (1)
packages/types/src/index.ts (2)
Frontend(39-39)Addons(44-44)
apps/cli/src/utils/addon-compatibility.ts (2)
packages/types/src/index.ts (2)
Addons(44-44)Frontend(39-39)apps/cli/src/constants.ts (1)
ADDON_COMPATIBILITY(114-122)
apps/cli/src/index.ts (4)
packages/types/src/index.ts (3)
AddInput(113-118)AddonsSchema(41-43)PackageManagerSchema(51-53)apps/cli/src/helpers/project-generation/detect-project-config.ts (1)
detectProjectConfig(6-33)apps/cli/src/prompts/add-addons-prompt.ts (1)
getAddonsToAdd(5-83)apps/cli/src/helpers/project-generation/add-addons.ts (1)
addAddonsToProject(14-168)
🪛 Gitleaks (8.26.0)
apps/cli/tsdown.config.ts
13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🔇 Additional comments (37)
packages/types/tsconfig.json (1)
1-22: tsconfig.json setup for@better-t-stack/typeslooks solid
The compiler options enable strict type checking, declaration output, and target ES2022 modules as intended.packages/types/src/index.ts (1)
1-158: Comprehensive Zod schemas and types look correct
The centralized type definitions cover all configuration options and enforce strict validation via Zod.apps/cli/src/helpers/project-generation/create-project.ts (2)
5-5: Import ofwriteBtsConfigis correctly placed
The new utility is imported alongside other helpers for consistency.
75-78: Initial BTS config is written at the right stage
Writingbts.jsoncbefore Git initialization ensures the config is included under version control.apps/cli/src/constants.ts (1)
114-123: Clarify semantics of empty compatibility arrays
Empty arrays are commented as “compatible with all,” but consumers might interpret them as “compatible with none.” Please verify the validation logic handles this correctly or use an explicit wildcard.package.json (4)
19-20: LGTM: Safe dependency updatesThe patch version updates for build tools are appropriate and should maintain compatibility.
Also applies to: 23-23
34-34: LGTM: Package manager updateUpdating to bun@1.2.16 brings the latest improvements and bug fixes.
35-38: LGTM: Workspace expansion supports new types packageAdding
packages/*to workspaces correctly enables the new@better-t-stack/typespackage structure.
27-29: LGTM: Improved lint-staged formattingThe multi-line array format enhances readability without changing functionality.
apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx (1)
29-29: LGTM: Clean removal of motion animationsThe replacement of
motion.divwith plaindivmaintains all styling and functionality while removing animation complexity. This aligns with the broader motion removal across the showcase components.Also applies to: 123-123
packages/types/package.json (2)
1-27: LGTM: Well-structured types package configurationThe package.json correctly sets up a shared types package with proper exports, dependencies, and scripts for the monorepo structure.
25-25: Verify TypeScript version consistencyThe TypeScript version
^5.8.3appears newer than the root workspace version5.7.3. Ensure version compatibility across the monorepo.#!/bin/bash # Check TypeScript versions across the monorepo echo "Root workspace TypeScript version:" jq -r '.devDependencies.typescript // .dependencies.typescript // "not found"' package.json echo -e "\nTypes package TypeScript version:" jq -r '.devDependencies.typescript // .dependencies.typescript // "not found"' packages/types/package.json echo -e "\nOther workspace TypeScript versions:" fd "package.json" --exclude node_modules --exec jq -r '(.name // "unknown") + ": " + (.devDependencies.typescript // .dependencies.typescript // "not found")' {}apps/web/src/app/(home)/showcase/page.tsx (1)
23-24: LGTM: Consistent motion animation removalAll
motion.divcomponents have been cleanly replaced with plaindivelements while preserving styling and structure. This aligns with the motion removal in the ShowcaseItem component.Also applies to: 66-66, 68-68, 72-72, 74-74, 90-92
apps/web/public/example-bts.jsonc (2)
1-20: LGTM: Comprehensive project configuration exampleThe configuration file provides a well-structured example with clear documentation, schema validation, and comprehensive stack choices.
2-2: Verify schema URL availabilityEnsure the schema URL
https://better-t-stack.dev/schema.jsonis accessible and contains the correct validation schema.#!/bin/bash # Check if the schema URL is accessible echo "Checking schema URL availability:" curl -I https://better-t-stack.dev/schema.json 2>/dev/null | head -n 1 echo -e "\nSchema content preview:" curl -s https://better-t-stack.dev/schema.json 2>/dev/null | head -n 10apps/web/scripts/generate-schema.ts (5)
1-12: LGTM! Clean imports from centralized types package.The imports are well-organized and leverage the new centralized
@better-t-stack/typespackage effectively.
16-25: LGTM! Proper extraction of enum values from Zod schemas.The use of
.optionsto extract enum values from Zod schemas is correct and maintains consistency with the type definitions.
112-127: LGTM! Comprehensive required fields definition.The required fields list covers all essential configuration properties and enforces a complete configuration structure.
130-137: LGTM! Proper async file operations with error handling.The function properly ensures directory existence and handles errors through the catch block on line 137.
41-41: Verify the semantic version pattern.The regex pattern
^\\d+\\.\\d+\\.\\d+$enforces basic semantic versioning but doesn't allow pre-release or build metadata (e.g.,1.0.0-alpha.1,1.0.0+build.1).What is the standard regex pattern for semantic versioning that includes pre-release and build metadata?apps/cli/package.json (3)
56-56: LGTM! Proper workspace dependency reference.Using
workspace:*for the internal types package ensures version consistency across the monorepo.
64-64: LGTM! Appropriate dependency for JSONC parsing.The
jsonc-simple-parserpackage is well-suited for parsing JSONC configuration files as mentioned in the AI summary.
68-68: LGTM! Reasonable dependency version updates.The version bumps for
zod,@types/node, andtsdownappear to be minor updates that should be safe.Also applies to: 72-73
apps/cli/src/prompts/add-addons-prompt.ts (1)
77-80: LGTM! Proper cancellation handling.The cancellation handling follows the clack prompts pattern correctly.
apps/cli/src/utils/addon-compatibility.ts (3)
1-28: LGTM! Well-designed compatibility validation function.The function properly handles the "compatible with all" case (empty array) and provides clear error messages for incompatible combinations.
30-46: LGTM! Clean filtering logic with proper exclusions.The function correctly filters out existing addons, the "none" option, and incompatible addons using the validation utility.
16-16: Good type assertion for compatibility check.The type assertion
as readonly string[]is necessary here to satisfy TypeScript's type checking while maintaining the const assertion in the constants file.apps/web/public/schema.json (3)
1-6: LGTM! Proper JSON Schema structure and metadata.The schema follows JSON Schema Draft 07 specification with appropriate title, description, and schema reference.
14-15: Consistent with generator script pattern.The version pattern matches the one defined in the generator script and enforces basic semantic versioning.
149-164: LGTM! Comprehensive validation with strict schema.The required fields list covers all essential properties and
additionalProperties: falseensures strict validation, preventing unexpected properties in configuration files.apps/cli/README.md (1)
30-211: Documentation looks comprehensive and well-structured!The new sections clearly explain the
addcommand functionality and the purpose of thebts.jsoncconfiguration file. The examples are helpful and the JSON snippet with comments is particularly useful for users.apps/cli/src/helpers/project-generation/add-addons.ts (1)
133-135: Good use of Set for deduplication!The approach to merge addons using Set ensures no duplicates are added to the configuration.
apps/cli/src/types.ts (1)
1-1: Clean type centralization!Moving all type definitions to a shared package is a good architectural decision that promotes consistency across the monorepo.
apps/web/package.json (1)
41-41: Good catch moving @types package to devDependencies!Moving
@types/papaparseto devDependencies is the correct approach as type definitions are only needed during development.apps/cli/src/helpers/project-generation/detect-project-config.ts (1)
6-43: Well-structured project detection utilities!Both functions handle errors gracefully and provide clear return values. The separation of concerns between checking project validity and reading configuration is good design.
apps/cli/src/index.ts (1)
354-378: LGTM! The router procedure follows established patterns.The new "add" procedure is well-structured and consistent with the existing "init" procedure. The input validation uses appropriate schemas from the types package, and the handler integration is clean.
apps/cli/src/utils/bts-config.ts (1)
13-13: ```shell
#!/bin/bashDisplay the contents of get-latest-cli-version.ts to verify sync behavior
sed -n '1,200p' apps/cli/src/utils/get-latest-cli-version.ts
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
| env: { | ||
| POSTHOG_API_KEY: "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs", | ||
| POSTHOG_HOST: "https://us.i.posthog.com", | ||
| MODE: process.env.MODE || "dev", // wierd trick i know | ||
| }, |
There was a problem hiding this comment.
Hard-coded API key exposed in source
Committing the PostHog API key is a security risk. Load it from the environment instead.
env: {
- POSTHOG_API_KEY: "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs",
+ POSTHOG_API_KEY: process.env.POSTHOG_API_KEY ?? "",
POSTHOG_HOST: "https://us.i.posthog.com",
MODE: process.env.MODE || "dev",
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| env: { | |
| POSTHOG_API_KEY: "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs", | |
| POSTHOG_HOST: "https://us.i.posthog.com", | |
| MODE: process.env.MODE || "dev", // wierd trick i know | |
| }, | |
| env: { | |
| - POSTHOG_API_KEY: "phc_8ZUxEwwfKMajJLvxz1daGd931dYbQrwKNficBmsdIrs", | |
| + POSTHOG_API_KEY: process.env.POSTHOG_API_KEY ?? "", | |
| POSTHOG_HOST: "https://us.i.posthog.com", | |
| MODE: process.env.MODE || "dev", // wierd trick i know | |
| }, |
🧰 Tools
🪛 Gitleaks (8.26.0)
13-13: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.
(generic-api-key)
🤖 Prompt for AI Agents
In apps/cli/tsdown.config.ts around lines 12 to 16, the PostHog API key is
hard-coded, which exposes sensitive information. Remove the hard-coded key and
instead load POSTHOG_API_KEY from process.env to keep it secure. Update the env
object to reference process.env.POSTHOG_API_KEY and ensure the key is set in the
environment before running the application.
| const availableAddons = [ | ||
| { | ||
| value: "biome" as const, | ||
| label: "Biome", | ||
| hint: "Fast formatter and linter for JavaScript, TypeScript, JSX", | ||
| compatible: true, | ||
| }, | ||
| { | ||
| value: "husky" as const, | ||
| label: "Husky", | ||
| hint: "Git hooks made easy", | ||
| compatible: true, | ||
| }, | ||
| { | ||
| value: "turborepo" as const, | ||
| label: "Turborepo", | ||
| hint: "High-performance build system for JavaScript and TypeScript", | ||
| compatible: true, | ||
| }, | ||
| { | ||
| value: "pwa" as const, | ||
| label: "PWA Support", | ||
| hint: "Progressive Web App features", | ||
| compatible: frontend.some((f) => | ||
| ["tanstack-router", "react-router", "solid"].includes(f), | ||
| ), | ||
| }, | ||
| { | ||
| value: "tauri" as const, | ||
| label: "Tauri", | ||
| hint: "Desktop application framework", | ||
| compatible: frontend.some((f) => | ||
| ["tanstack-router", "react-router", "nuxt", "svelte", "solid"].includes( | ||
| f, | ||
| ), | ||
| ), | ||
| }, | ||
| { | ||
| value: "starlight" as const, | ||
| label: "Starlight", | ||
| hint: "Documentation site with Astro", | ||
| compatible: true, | ||
| }, | ||
| ]; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Refactor to use centralized addon definitions and compatibility utilities.
This hardcoded addon list duplicates logic that should be centralized. The compatibility checks here (lines 35-37, 43-47) are inconsistent with the ADDON_COMPATIBILITY constant and validateAddonCompatibility utility.
Consider refactoring to use the centralized utilities:
+import { ADDON_COMPATIBILITY } from "../constants";
+import { getCompatibleAddons } from "../utils/addon-compatibility";
export async function getAddonsToAdd(
frontend: Frontend[],
existingAddons: Addons[] = [],
): Promise<Addons[]> {
- const options: { value: Addons; label: string; hint: string }[] = [];
-
- // Filter out addons that are already present
- const availableAddons = [
- // ... hardcoded definitions
- ];
-
- for (const addon of availableAddons) {
- if (!existingAddons.includes(addon.value) && addon.compatible) {
- options.push({
- value: addon.value,
- label: addon.label,
- hint: addon.hint,
- });
- }
- }
+ const addonMetadata = {
+ biome: { label: "Biome", hint: "Fast formatter and linter for JavaScript, TypeScript, JSX" },
+ husky: { label: "Husky", hint: "Git hooks made easy" },
+ // ... other metadata
+ };
+
+ const compatibleAddons = getCompatibleAddons(
+ Object.keys(ADDON_COMPATIBILITY) as Addons[],
+ frontend,
+ existingAddons
+ );
+
+ const options = compatibleAddons.map(addon => ({
+ value: addon,
+ label: addonMetadata[addon].label,
+ hint: addonMetadata[addon].hint,
+ }));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const availableAddons = [ | |
| { | |
| value: "biome" as const, | |
| label: "Biome", | |
| hint: "Fast formatter and linter for JavaScript, TypeScript, JSX", | |
| compatible: true, | |
| }, | |
| { | |
| value: "husky" as const, | |
| label: "Husky", | |
| hint: "Git hooks made easy", | |
| compatible: true, | |
| }, | |
| { | |
| value: "turborepo" as const, | |
| label: "Turborepo", | |
| hint: "High-performance build system for JavaScript and TypeScript", | |
| compatible: true, | |
| }, | |
| { | |
| value: "pwa" as const, | |
| label: "PWA Support", | |
| hint: "Progressive Web App features", | |
| compatible: frontend.some((f) => | |
| ["tanstack-router", "react-router", "solid"].includes(f), | |
| ), | |
| }, | |
| { | |
| value: "tauri" as const, | |
| label: "Tauri", | |
| hint: "Desktop application framework", | |
| compatible: frontend.some((f) => | |
| ["tanstack-router", "react-router", "nuxt", "svelte", "solid"].includes( | |
| f, | |
| ), | |
| ), | |
| }, | |
| { | |
| value: "starlight" as const, | |
| label: "Starlight", | |
| hint: "Documentation site with Astro", | |
| compatible: true, | |
| }, | |
| ]; | |
| // apps/cli/src/prompts/add-addons-prompt.ts | |
| import { ADDON_COMPATIBILITY } from "../constants"; | |
| import { getCompatibleAddons } from "../utils/addon-compatibility"; | |
| export async function getAddonsToAdd( | |
| frontend: Frontend[], | |
| existingAddons: Addons[] = [], | |
| ): Promise<Addons[]> { | |
| const addonMetadata: Record<Addons, { label: string; hint: string }> = { | |
| biome: { | |
| label: "Biome", | |
| hint: "Fast formatter and linter for JavaScript, TypeScript, JSX", | |
| }, | |
| husky: { | |
| label: "Husky", | |
| hint: "Git hooks made easy", | |
| }, | |
| turborepo: { | |
| label: "Turborepo", | |
| hint: "High-performance build system for JavaScript and TypeScript", | |
| }, | |
| pwa: { | |
| label: "PWA Support", | |
| hint: "Progressive Web App features", | |
| }, | |
| tauri: { | |
| label: "Tauri", | |
| hint: "Desktop application framework", | |
| }, | |
| starlight: { | |
| label: "Starlight", | |
| hint: "Documentation site with Astro", | |
| }, | |
| }; | |
| const compatibleAddons = getCompatibleAddons( | |
| Object.keys(ADDON_COMPATIBILITY) as Addons[], | |
| frontend, | |
| existingAddons, | |
| ); | |
| const options = compatibleAddons.map(addon => ({ | |
| value: addon, | |
| label: addonMetadata[addon].label, | |
| hint: addonMetadata[addon].hint, | |
| })); | |
| // …the rest of your prompt logic, e.g. calling selectMulti with `options` | |
| } |
🤖 Prompt for AI Agents
In apps/cli/src/prompts/add-addons-prompt.ts between lines 12 and 55, the addon
list is hardcoded with compatibility checks that duplicate and diverge from the
centralized ADDON_COMPATIBILITY constant and validateAddonCompatibility utility.
Refactor this code to import and use the centralized addon definitions and
compatibility utilities instead of hardcoding values and compatibility logic.
Replace the current availableAddons array with one constructed from the
centralized definitions, ensuring compatibility flags are derived via the
validateAddonCompatibility function for consistency and maintainability.
e063db9 to
62eb306
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
apps/cli/src/helpers/project-generation/add-addons.ts (1)
71-106: Use centralized addon compatibility validationThe addon compatibility checks are hardcoded here, but based on the AI summary, there are centralized compatibility utilities in
apps/cli/src/utils/addon-compatibility.ts. This matches the previous review feedback and should be addressed to maintain consistency and avoid duplication.Replace the manual frontend compatibility checks with calls to the centralized utility functions:
-// Validate addon compatibility -for (const addon of input.addons) { - if (addon === "pwa") { - const hasCompatibleFrontend = config.frontend.some((f) => - ["tanstack-router", "react-router", "solid"].includes(f), - ); - if (!hasCompatibleFrontend) { - cancel( - pc.red( - "PWA addon requires React (TanStack Router/React Router) or SolidJS frontend", - ), - ); - process.exit(1); - } - } - - if (addon === "tauri") { - const hasCompatibleFrontend = config.frontend.some((f) => - [ - "tanstack-router", - "react-router", - "nuxt", - "svelte", - "solid", - ].includes(f), - ); - if (!hasCompatibleFrontend) { - cancel( - pc.red( - "Tauri addon requires React, Nuxt, SvelteKit, or SolidJS frontend", - ), - ); - process.exit(1); - } - } -} +// Import the compatibility utilities at the top +import { validateAddonCompatibility } from "../../utils/addon-compatibility"; + +// Validate addon compatibility using centralized utilities +for (const addon of input.addons) { + const isCompatible = validateAddonCompatibility(addon, config.frontend); + if (!isCompatible) { + const compatibilityError = getAddonCompatibilityError(addon, config.frontend); + cancel(pc.red(compatibilityError)); + process.exit(1); + } +}
🧹 Nitpick comments (2)
apps/cli/src/helpers/project-generation/add-addons.ts (2)
50-69: Consider extracting config mapping logicThe config object construction is quite verbose and mixes detected values with input values. Consider extracting this mapping logic into a separate utility function for better maintainability.
+// Extract to a utility function like `createProjectConfigFromDetected` +const config = createProjectConfigFromDetected(detectedConfig, input, projectDir); -const config: ProjectConfig = { - projectName: detectedConfig.projectName || path.basename(projectDir), - projectDir, - relativePath: ".", - database: detectedConfig.database || "none", - orm: detectedConfig.orm || "none", - backend: detectedConfig.backend || "none", - runtime: detectedConfig.runtime || "none", - frontend: detectedConfig.frontend || [], - addons: input.addons, - examples: detectedConfig.examples || [], - auth: detectedConfig.auth || false, - git: false, // Not relevant for adding addons - packageManager: - input.packageManager || detectedConfig.packageManager || "npm", - install: input.install || false, - dbSetup: detectedConfig.dbSetup || "none", - api: detectedConfig.api || "none", -};
153-168: Consider consolidating error handlingThe nested try-catch blocks have some redundancy in error handling logic. Consider extracting common error handling patterns or simplifying the structure.
-} catch (error) { - addSpinner.stop(pc.red("Failed to add addons")); - throw error; -} -} catch (error) { -if (error instanceof Error) { - cancel(pc.red(`Error adding addons: ${error.message}`)); - console.error(error.stack); - process.exit(1); -} else { - cancel(pc.red(`An unexpected error occurred: ${String(error)}`)); - console.error(error); - process.exit(1); -} -} +} catch (error) { + addSpinner.stop(pc.red("Failed to add addons")); + handleAddonInstallationError(error); +} +} catch (error) { + handleAddonInstallationError(error); +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (19)
apps/cli/README.md(5 hunks)apps/cli/package.json(1 hunks)apps/cli/src/constants.ts(1 hunks)apps/cli/src/helpers/project-generation/add-addons.ts(1 hunks)apps/cli/src/helpers/project-generation/create-project.ts(2 hunks)apps/cli/src/helpers/project-generation/detect-project-config.ts(1 hunks)apps/cli/src/index.ts(3 hunks)apps/cli/src/prompts/add-addons-prompt.ts(1 hunks)apps/cli/src/types.ts(1 hunks)apps/cli/src/utils/addon-compatibility.ts(1 hunks)apps/cli/src/utils/bts-config.ts(1 hunks)apps/cli/tsdown.config.ts(1 hunks)apps/web/package.json(3 hunks)apps/web/public/example-bts.jsonc(1 hunks)apps/web/public/schema.json(1 hunks)apps/web/scripts/generate-schema.ts(1 hunks)apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx(2 hunks)apps/web/src/app/(home)/showcase/page.tsx(3 hunks)package.json(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- apps/cli/src/utils/addon-compatibility.ts
- apps/web/public/example-bts.jsonc
🚧 Files skipped from review as they are similar to previous changes (16)
- apps/cli/tsdown.config.ts
- apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx
- apps/cli/src/helpers/project-generation/create-project.ts
- apps/web/src/app/(home)/showcase/page.tsx
- apps/cli/src/constants.ts
- apps/web/scripts/generate-schema.ts
- apps/cli/src/prompts/add-addons-prompt.ts
- apps/cli/README.md
- apps/cli/package.json
- package.json
- apps/cli/src/helpers/project-generation/detect-project-config.ts
- apps/cli/src/types.ts
- apps/cli/src/index.ts
- apps/cli/src/utils/bts-config.ts
- apps/web/public/schema.json
- apps/web/package.json
🔇 Additional comments (4)
apps/cli/src/helpers/project-generation/add-addons.ts (4)
1-12: LGTM: Clean import organizationThe imports are well-organized with clear separation between Node.js modules, external libraries, and internal modules. The type imports are properly handled.
14-31: LGTM: Robust project validationThe function signature is well-typed and the initial project validation logic properly ensures the command is run from a Better-T Stack project directory with appropriate error handling and user feedback.
108-118: LGTM: Clear user feedbackThe configuration display provides excellent user visibility into what was detected and what will be added, enhancing the user experience.
120-152: LGTM: Well-structured addon installation flowThe addon installation logic is well-organized with proper progress feedback, error handling, and conditional dependency installation. The configuration update logic correctly merges existing and new addons.
1cdb5b6 to
83bf7eb
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
apps/cli/src/helpers/project-generation/add-addons.ts (1)
62-76: Good use of centralized addon compatibility validation.The code correctly uses the
validateAddonCompatibilityutility from the centralized compatibility module, ensuring consistency across the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (20)
apps/cli/README.md(5 hunks)apps/cli/package.json(1 hunks)apps/cli/src/constants.ts(1 hunks)apps/cli/src/helpers/project-generation/add-addons.ts(1 hunks)apps/cli/src/helpers/project-generation/create-project.ts(2 hunks)apps/cli/src/helpers/project-generation/detect-project-config.ts(1 hunks)apps/cli/src/index.ts(3 hunks)apps/cli/src/prompts/addons.ts(2 hunks)apps/cli/src/types.ts(2 hunks)apps/cli/src/utils/addon-compatibility.ts(1 hunks)apps/cli/src/utils/bts-config.ts(1 hunks)apps/web/package.json(3 hunks)apps/web/public/example-bts.jsonc(1 hunks)apps/web/public/schema.json(1 hunks)apps/web/scripts/generate-schema.ts(1 hunks)apps/web/src/app/(home)/_components/stack-builder.tsx(0 hunks)apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx(2 hunks)apps/web/src/app/(home)/showcase/page.tsx(3 hunks)biome.json(1 hunks)package.json(1 hunks)
💤 Files with no reviewable changes (1)
- apps/web/src/app/(home)/_components/stack-builder.tsx
✅ Files skipped from review due to trivial changes (1)
- apps/web/public/schema.json
🚧 Files skipped from review as they are similar to previous changes (15)
- biome.json
- apps/cli/src/helpers/project-generation/create-project.ts
- apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx
- apps/web/src/app/(home)/showcase/page.tsx
- package.json
- apps/web/scripts/generate-schema.ts
- apps/cli/src/constants.ts
- apps/web/public/example-bts.jsonc
- apps/cli/src/types.ts
- apps/cli/src/utils/addon-compatibility.ts
- apps/cli/src/helpers/project-generation/detect-project-config.ts
- apps/cli/package.json
- apps/cli/src/index.ts
- apps/web/package.json
- apps/cli/src/utils/bts-config.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/cli/src/prompts/addons.ts (2)
apps/cli/src/types.ts (3)
Addons(44-44)Frontend(39-39)AddonsSchema(41-43)apps/cli/src/utils/addon-compatibility.ts (2)
validateAddonCompatibility(4-28)getCompatibleAddons(30-46)
🔇 Additional comments (6)
apps/cli/README.md (2)
71-154: Excellent documentation for the new add command.The documentation clearly explains the new addon addition functionality with comprehensive usage examples and options. The examples cover both interactive and non-interactive usage patterns effectively.
180-212: Clear explanation of the bts.jsonc configuration file.The documentation effectively explains the purpose and structure of the configuration file, including its role in project detection and addon management. The example JSON snippet helps users understand the format.
apps/cli/src/helpers/project-generation/add-addons.ts (1)
15-119: Well-structured addon addition logic.The function follows a logical flow: project validation, configuration detection, compatibility checking, setup, and config updates. The error handling and user feedback are appropriate.
apps/cli/src/prompts/addons.ts (3)
16-53: Well-designed centralized display logic.The
getAddonDisplayhelper function centralizes label and hint generation with support for recommended flags, improving maintainability and consistency.
61-83: Improved dynamic addon option generation.The refactored logic uses schema-driven addon generation with centralized compatibility validation, replacing hardcoded options. The sorting logic that prioritizes turborepo is a nice UX touch.
108-148: Effective addon addition for existing projects.The new
getAddonsToAddfunction properly handles incremental addon selection by filtering out existing addons and ensuring compatibility. The early return for empty options prevents unnecessary user interaction.
83bf7eb to
5d1b4c3
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
apps/cli/src/prompts/addons.ts (1)
101-103: Inconsistent auto-addition logic between functions.The auto-addition of "biome" when "husky" is selected exists in
getAddonsChoicebut not ingetAddonsToAdd. This creates inconsistent behavior between initial project creation and adding addons later.Apply this fix to maintain consistency:
if (isCancel(response)) { cancel(pc.red("Operation cancelled")); process.exit(0); } + if (response.includes("husky") && !response.includes("biome")) { + response.push("biome"); + } + return response;Add this logic to the
getAddonsToAddfunction around line 145.
🧹 Nitpick comments (3)
apps/cli/src/prompts/addons.ts (3)
61-83: Verify the "recommended" flag usage and consider more sophisticated sorting.Two observations:
Line 69 always passes
trueforisRecommended- ensure all compatible addons should indeed be marked as recommended in the initial selection flow.The sorting only prioritizes "turborepo" but could benefit from a more comprehensive sorting strategy for better UX.
Consider this enhancement for more flexible sorting:
- const options = allPossibleOptions.sort((a, b) => { - if (a.value === "turborepo") return -1; - if (b.value === "turborepo") return 1; - return 0; - }); + const ADDON_PRIORITY = { turborepo: 1, biome: 2, husky: 3 }; + const options = allPossibleOptions.sort((a, b) => { + const priorityA = ADDON_PRIORITY[a.value] || 999; + const priorityB = ADDON_PRIORITY[b.value] || 999; + return priorityA - priorityB; + });
108-148: Consider improving user feedback and message differentiation.The new
getAddonsToAddfunction is well-implemented, but consider these improvements:
Both functions use the same message "Select addons" which might confuse users about the context (initial vs. incremental selection).
When no compatible addons are available (lines 132-134), users aren't informed about this situation.
Apply these improvements:
const response = await multiselect<Addons>({ - message: "Select addons", + message: "Select addons to add to your project", options: options, required: true, });And consider adding user feedback for the empty case:
if (options.length === 0) { + console.log(pc.yellow("No additional compatible addons available for your project.")); return []; }
96-99: Consider extracting common cancellation handling.Both functions have identical cancellation handling logic that could be extracted to a utility function for better maintainability.
Create a utility function:
// In a utilities file export function handleCancellation() { cancel(pc.red("Operation cancelled")); process.exit(0); }Then replace both occurrences with:
if (isCancel(response)) { - cancel(pc.red("Operation cancelled")); - process.exit(0); + handleCancellation(); }Also applies to: 142-145
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (19)
apps/cli/package.json(1 hunks)apps/cli/src/constants.ts(1 hunks)apps/cli/src/helpers/project-generation/add-addons.ts(1 hunks)apps/cli/src/helpers/project-generation/create-project.ts(2 hunks)apps/cli/src/helpers/project-generation/detect-project-config.ts(1 hunks)apps/cli/src/index.ts(3 hunks)apps/cli/src/prompts/addons.ts(2 hunks)apps/cli/src/types.ts(2 hunks)apps/cli/src/utils/addon-compatibility.ts(1 hunks)apps/cli/src/utils/bts-config.ts(1 hunks)apps/web/package.json(3 hunks)apps/web/public/example-bts.jsonc(1 hunks)apps/web/public/schema.json(1 hunks)apps/web/scripts/generate-schema.ts(1 hunks)apps/web/src/app/(home)/_components/stack-builder.tsx(0 hunks)apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx(2 hunks)apps/web/src/app/(home)/showcase/page.tsx(3 hunks)biome.json(1 hunks)package.json(1 hunks)
💤 Files with no reviewable changes (1)
- apps/web/src/app/(home)/_components/stack-builder.tsx
✅ Files skipped from review due to trivial changes (2)
- apps/cli/src/utils/addon-compatibility.ts
- apps/web/public/schema.json
🚧 Files skipped from review as they are similar to previous changes (15)
- biome.json
- apps/cli/src/helpers/project-generation/create-project.ts
- apps/web/src/app/(home)/showcase/_components/ShowcaseItem.tsx
- apps/web/src/app/(home)/showcase/page.tsx
- apps/cli/src/constants.ts
- package.json
- apps/web/public/example-bts.jsonc
- apps/web/scripts/generate-schema.ts
- apps/cli/src/types.ts
- apps/cli/src/helpers/project-generation/add-addons.ts
- apps/cli/package.json
- apps/cli/src/helpers/project-generation/detect-project-config.ts
- apps/cli/src/index.ts
- apps/web/package.json
- apps/cli/src/utils/bts-config.ts
🔇 Additional comments (2)
apps/cli/src/prompts/addons.ts (2)
4-8: LGTM! Clean imports for the new compatibility system.The imports are well-organized and properly typed, integrating the new addon compatibility utilities.
16-53: Excellent refactoring - centralizes display logic effectively.The
getAddonDisplayhelper function is well-structured with proper fallback handling and conditional messaging based on theisRecommendedparameter.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/cli/src/helpers/project-generation/add-addons.ts (1)
100-103: Improve error handling specificity.The generic error handling could be more specific to help users understand different failure scenarios.
Consider handling specific error types differently:
} catch (error) { - const message = error instanceof Error ? error.message : String(error); - exitWithError(`Error adding addons: ${message}`); + if (error instanceof Error) { + console.error('Stack trace:', error.stack); + exitWithError(`Error adding addons: ${error.message}`); + } else { + exitWithError(`Unexpected error adding addons: ${String(error)}`); + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/cli/src/helpers/project-generation/add-addons.ts(1 hunks)apps/cli/src/helpers/setup/addons-setup.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/cli/src/helpers/setup/addons-setup.ts (1)
apps/cli/src/types.ts (1)
ProjectConfig(124-141)
apps/cli/src/helpers/project-generation/add-addons.ts (7)
apps/cli/src/types.ts (3)
AddInput(113-118)Addons(44-44)ProjectConfig(124-141)apps/cli/src/helpers/project-generation/detect-project-config.ts (2)
isBetterTStackProject(35-43)detectProjectConfig(6-33)apps/cli/src/utils/addon-compatibility.ts (1)
validateAddonCompatibility(4-27)apps/cli/src/helpers/project-generation/template-manager.ts (1)
setupAddonsTemplate(547-583)apps/cli/src/helpers/setup/addons-setup.ts (1)
setupAddons(10-64)apps/cli/src/utils/bts-config.ts (1)
updateBtsConfig(92-120)apps/cli/src/helpers/project-generation/install-dependencies.ts (1)
installDependencies(7-32)
🔇 Additional comments (6)
apps/cli/src/helpers/setup/addons-setup.ts (2)
10-10: LGTM: Backward compatible function signature enhancement.The addition of the optional
isAddCommandparameter with a default value maintains backward compatibility while enabling conditional behavior for the add command flow.
27-39: LGTM: Helpful user guidance for turborepo addon.The conditional logging provides clear, actionable instructions to users when adding the turborepo addon via the CLI. The message formatting is consistent with the project's styling patterns and includes a helpful documentation link.
apps/cli/src/helpers/project-generation/add-addons.ts (4)
15-18: LGTM: Clean error handling utility.The
exitWithErrorhelper provides consistent error handling with proper user feedback and process termination.
60-71: LGTM: Proper addon compatibility validation.The implementation correctly uses the centralized
validateAddonCompatibilityutility and provides clear error messages for incompatible addons. This addresses the previous review concern about using centralized compatibility validation.
82-84: LGTM: Proper addon merging with deduplication.The code correctly merges existing addons with new ones using
Setto avoid duplicates, ensuring idempotent addon addition.
40-58: Review the hardcoded fallback values in config construction.Several fallback values may not be appropriate when adding addons to existing projects:
git: false(line 52) - This should likely preserve the existing git setting or detect it from the projectrelativePath: "."(line 43) - This might not be accurate for all project structures- Default values for
database,orm,backend, etc. - These should ideally come from detected config or fail if detection fails#!/bin/bash # Description: Check how other parts of the codebase handle ProjectConfig construction # Expected: Find patterns for config construction to ensure consistency # Search for other ProjectConfig construction patterns ast-grep --pattern 'const $_ : ProjectConfig = { $$$ }' # Search for git detection patterns rg -A 5 "git.*detect|detect.*git" --type ts
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Chores